﻿using Abp.Application.Services;
using FutureApp.Cms.Dto;
using System;
using Abp.Domain.Repositories;
using System.Linq;

namespace FutureApp.Cms
{
    /// <AppService/>
    public class MessageAppService
        : AsyncCrudAppService<Message, MessageEntityDto, Guid, GetAllMessageInput, CreateMessageInput>,
        IMessageAppService
    {
        /// <constructor/>
        public MessageAppService(IRepository<Message, Guid> repository)
            : base(repository)
        {

        }

        /// <inheritDoc/>
        protected override Message MapToEntity(CreateMessageInput createInput)
        {
            var entity = base.MapToEntity(createInput);
            entity.SendTime = DateTime.Now;
            return entity;
        }

        /// <inheritDoc/>
        protected override IQueryable<Message> ApplySorting(IQueryable<Message> query, GetAllMessageInput input)
        {
            //return base.ApplySorting(query, input);
            return query.OrderByDescending(e => e.CreationTime);
        }
    }
}
